<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler'>
      <f-search-form-item label='订单编号' name='orderNo' />
      <f-search-form-item label='部门' ref='dept' name='deptId' slot='advanced' type='select' :data='api.dept.list' valueKey='deptId' label-key='deptName' />
      <f-search-form-item label='订单日期' type='range' name='beginDate' />
    </f-search-form>
    <f-table ref='table' size='small' rowKey='orderId' :showSetting='false' setting-key='order_task_todo_tab1' :tableColumns='columns' :scroll='{x:true}' :multiple='false' :operator='operator' :params='queryParam' :api='api.tasktodo' handler='hyOrderTaskTodoListHandler'>
      <span slot='sendType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text==1'>现款</a-tag>
            <a-tag color='#FF0000' v-if='text==2'>预收款</a-tag>
            <a-tag color='#87d068' v-if='text==3'>资保金</a-tag>
            <a-tag color='purple' v-if='text==4'>全额资信</a-tag>
      </span>
      <span slot='deptType' slot-scope='text, record, index'>
        <a-tag color='#87d068' v-if='text=="ZS"'>招商</a-tag>
        <a-tag color='#108ee9' v-if='text=="ZY"'>自营</a-tag>
      </span>
      <span slot='taskName' slot-scope='text, record, index'>
        <a-tag color='purple'>{{ record.taskName }}</a-tag>
      </span>
      <span slot='printTag' slot-scope='text, record, index'>
         <a-tag color='#87d068' v-if='text==0'>未打印</a-tag>
         <a-tag color='purple' v-if='text>=1'>已打印</a-tag>
      </span>
      <span slot='action' slot-scope='text, record'>
          <template>
<!--            <a v-if="record.endTime==''&&record.assignee!=''&& record.assignee!='' && record.revokeState==0" @click='$refs.drawer.showDrawer(record)'>办理</a>-->
            <a v-if="record.assignee=='' && record.revokeState==0" @click='claimTask(record)'>认领</a>
            <a-divider type='vertical' v-if="record.assignee=='' && record.revokeState==0" />
            <a v-if="record.assignee!='' && record.revokeState==0" @click='$refs.approveDrawer.showDrawer(record)'>办理</a>
            <a-divider type='vertical' v-if="record.assignee!='' || record.revokeState==1" />
            <a href='javascript:;' @click='printOrder(record)'>发货单</a>
             <a-divider type='vertical'  />
          </template>
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
               <a-menu-item v-if="record.assignee===$store.getters.userInfo.nickName && record.endTime=='' && record.revokeState==0">
                <a href='javascript:;' @click='unClaimTask(record)'>取消认领</a>
              </a-menu-item>
              <a-menu-item>
                <a href='javascript:;' @click='processImg(record)'>审批进度</a>
              </a-menu-item>
               <a-menu-item v-if='!record.orderId'>
                  <a href='javascript:;' @click='deleteProcessInstance(record.processInstanceId)'>删除无效数据</a>
               </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <print-modal ref='printModal' :showPrint='isXs'></print-modal>
    <task-todo-drawer ref='drawer' @success='onLoad' taskHandlerName='hyOrderTaskDataHandler'></task-todo-drawer>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <hy-order-approve-drawer ref='approveDrawer' @success='onLoad'></hy-order-approve-drawer>
  </div>
</template>
<script>

import api from "../../js/api"
import TaskTodoDrawer from "../tasktodo_drawer"
import ProcessImage from "../../../flowable/process/process_image"
import HyOrderApproveDrawer from "./approve/hyorder_approve_drawer"
import { processMixins } from "@/core/mixins/processMixins"

import PrintModal from "@/views/module/haiying/print/print_modal"
export default {
  name: "TodoNo",
  components: {
    HyOrderApproveDrawer,
    ProcessImage,
    PrintModal,
    TaskTodoDrawer
  },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []
    let isXs = this.$store.state.user.roleInfo.isXs==true
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      processInstanceId: "",
      superAdmin: this.superAdmin,
      isXs:isXs,
      processImageVisible: false,
      // 表头
      columns: [
        {
          title: "序号",
          width: "50px",
          align: "center",
          fixed: "left",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "订单编号",
          align: "left",
          fixed: "left",
          width: "130px",
          dataIndex: "orderNo"
        },
        {
          title: "制单日期",
          align: "center",
          width: "100px",
          dataIndex: "createDate"
        },
        {
          title: "账套",
          align: "left",
          width: "130px",
          ellipsis: true,
          dataIndex: "companyName"
        },
        {
          title: "业务类型",
          align: "center",
          width: "80px",
          dataIndex: "deptType",
          scopedSlots: { customRender: "deptType" }
        },
        {
          title: "发货区域",
          align: "left",
          width: "80px",
          dataIndex: "sendArea"
        },
        {
          title: "发货方式",
          align: "left",
          dataIndex: "sendType",
          scopedSlots: { customRender: "sendType" }
        },
        {
          title: "部门",
          align: "left",
          width: "120px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "left",
          width: "90px",
          ellipsis: true,
          dataIndex: "saleManName"
        },
        {
          title: "业务编码",
          align: "left",
          width: "120px",
          dataIndex: "businessCode"
        },
        {
          title: "单位名称",
          align: "left",
          ellipsis: true,
          width: "120px",
          dataIndex: "customName"
        },
        {
          title: "发货金额",
          align: "left",
          width: "90px",
          dataIndex: "totalSaleAmount"
        },
        {
          title: "制单人",
          align: "left",
          width: "90px",
          dataIndex: "nickName"
        },
        {
          title: "创建日期",
          align: "center",
          width: "150px",
          dataIndex: "createTime"
        },
        {
          title: "打印状态",
          align: "center",
          width: "100px",
          fixed: "right",
          isColumnHidden:true,
          dataIndex: "printTag",
          scopedSlots: { customRender: "printTag" }
        },
        {
          title: "订单状态",
          fixed: "right",
          align: "left",
          dataIndex: "taskName",
          scopedSlots: { customRender: "taskName" }
        },
        {
          title: "操作",
          align: "center",
          width: "180px",
          dataIndex: "action",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },
    printOrder(record) {
      this.$refs["printModal"].open(record.orderId, 1)
    }
  }
}
</script>
